Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

154
Vistas
remove "?" from all anchor text

I am trying to remove the ? character from all anchor href values with Javascript. For example, there are many URLs like this:

<a href="https://example.com/something/?">my anchor</a>

I tried this but getting the error index of is not a function

var url = jQuery("a");
var a = url.indexOf("?");
var b =  url.substring(a);
var c = url.replace(b,"");
url = c;
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

To achieve this you can provide a function to prop() which runs against all elements in the collection. In the function you can accept the current href value as an argument then use replace() to remove the ? characters:

$('a').prop('href', (i, h) => h.replace(/\?/g, ''));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="https://example.com/something/?">my anchor 1</a>
<a href="https://example.com/somethingelse/?">my anchor 2</a>
<a href="https://example.com/?something">my anchor 2</a>

Note that this will replace all instances of ? from anywhere in the href value. If you only want to remove it from the end of the string change the regex to /\?$/g

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda